home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************
- * TEXTRA AREXX script -- Mike Haas, 1991, All Rights Reserved. *
- * Freely distributable ONLY as a component of the TEXTRA package. *
- * This banner may not be removed or altered (improvements to the *
- * actual program welcome). Please document and send to me. *
- * !!! PLACE THIS FILE IN YOUR REXX: DIRECTORY !!! *
- ******************************************************************/
-
- /*
- ** zDotIf.textra Mike Haas
- **
- ** Convienient for disabling sections of code in Forth from being
- ** acted on by the interpreter/compiler. It adds "0 .IF" and a ".THEN"
- ** around the selected lines, and by default, includes them within a
- ** [ and ] characters, so that the statements are appropriate for
- ** use while compiling. (For JForth, these statements are very
- ** similar to "#if 0" and "#endif" are to C.)
- **
- ** To have this script insert statements suitable for the interpreter,
- ** (in other words, not enclosed within [ and ]), provide any argument.
- ** It doesn't matter what it is; it is the lack of an argument which
- ** triggers the [ and ] encapsulation.
- **
- ** Just select some lines of text and enter: zDotIf
- **
- ** or...
- **
- ** zDotIf <anything>
- **
- ** Note that if you select text which contains "0 .IF" or "[ 0 .IF ]"
- ** for the first line, this script will assume that the last selected
- ** line is the corresponding .THEN statement. It will then delete the
- ** first and last selected lines, re-enabling that text to the JForth
- ** compiler/interpreter.
- */
-
- OPTIONS results
-
- rex = 0; result = "NOTSUPPORTED" /*00001*/
- textraversion
- parse var result maj min rex
- if (result == "NOTSUPPORTED") | (rex < 3) then do
- notify "Textra V1.13 or later required for this script."
- exit
- end
-
- parse arg nobracket
-
- get select position
-
- if (result == "NO SELECT") then /* is nothing selected? */
-
- do
- notify "There must be a select range to comment/uncomment."
- exit
- end
-
-
- /* yes, there is a selection, get it's boundaries */
- parse var result startx ' ' starty ' ' endx ' ' endy
-
- currx = startx
- curry = starty
-
- /* if nothing on the endline is actually selected, don't include it */
- if (endx == 0) then endy = endy - 1
-
-
- /*
- ** check if we are to delete an existing set
- */
-
- get line starty
- if (result = "0 .IF") | (result = "[ 0 .IF ]") then do
-
- /*
- ** yep, take it out
- */
- selectline endy
- del
- selectline starty
- del
-
- end
- else do
-
- /*
- ** nope, put 'em in
- */
- line starty
- if (nobracket ~= "") then
- textn "0 .IF"
- else
- textn "[ 0 .IF ]"
-
- line endy+2
- if (nobracket ~= "") then
- textn ".THEN"
- else
- textn "[ .THEN ]"
-
- end
-